package com.example.hanfu_bk.mapper;

import com.example.hanfu_bk.pojo.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    // 根据手机号查询用户
    @Select("select * from user where phone = #{phone}")
    User selectByPhone(String phone);

    // 根据ID查询用户
    @Select("select * from user where id = #{id}")
    User selectById(Integer id);

    // 注册用户
    @Insert("insert into user(avatar, nickname, phone, password, favorite_thing) " +
            "values(#{avatar}, #{nickname}, #{phone}, #{password}, #{favoriteThing})")
    int register(User user);

    // 更新登录状态
    @Update("update user set is_login = #{isLogin} where id = #{id}")
    int updateLoginStatus(User user);

    // 更新用户信息
    @Update("update user set avatar = #{avatar}, nickname = #{nickname} where id = #{id}")
    int updateUserInfo(User user);

    // 更新密码
    @Update("update user set password = #{password} where phone = #{phone}")
    int updatePassword(User user);

    // 更新密码
    @Update("update user set password = #{password} where id = #{id}")
    int updatePasswordById(User user);

    // 更新密保答案（假设字段为favorite_thing）
    @Update("update user set favorite_thing = #{favoriteThing} where id = #{id}")
    int updateSecurityAnswer(User user);

    // 物理删除用户
    @Delete("delete from user where id = #{id}")
    int deleteById(Integer id);
}